package io.renren.modules.question.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.question.dao.CommonQuestionDao;
import io.renren.modules.question.entity.CommonQuestionEntity;
import io.renren.modules.question.service.CommonQuestionService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class CommonQuestionServiceImpl extends ServiceImpl<CommonQuestionDao, CommonQuestionEntity> implements CommonQuestionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        IPage<CommonQuestionEntity> page = new Query<CommonQuestionEntity>().getPage(params);

        LambdaQueryWrapper<CommonQuestionEntity> wrapper = null;
        //根据标题模糊查询
        if (params.get("title") != null) {
            wrapper = Wrappers.<CommonQuestionEntity>lambdaQuery()
                    .like(CommonQuestionEntity::getTitle,params.get("title"));
        }

        IPage<CommonQuestionEntity> pageResult = this.page(page, wrapper);
        return new PageUtils(pageResult);
    }
}
